#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
#include<limits.h>

struct TreeNode 
{
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};
 
int minDepth(struct TreeNode* root)
{
    if (root == NULL)
        return 0;
    if (root->left == NULL && root->right == NULL)
        return 1;
    int x = INT_MAX;
    if (root->left != NULL)
        x = fmin(minDepth(root->left), x);
    if (root->right != NULL)
        x = fmin(minDepth(root->right), x);
    return x + 1;
}